﻿Public Class clsRede
    Inherits clsConexao
    Private fComposta As Byte, fUnica As Byte, fTamanho_Barra As Byte, fArredonda As Byte, fPreco As Byte, fFormata As Byte, fPropria As Byte, fPreco_Decimal As Byte, fComposta2 As Byte, fUnica2 As Byte, fArredonda2 As Byte, fPreco2 As Byte, fFormata2 As Byte, fPropria2 As Byte, fAtacado As Byte, fQtd As Byte, fComunicacao As Byte, fPedido As Byte, fDistribuicao As Byte, fCor_Fornecedor As Byte, fFidelidade As Byte
    Private fCodigo As String = "", fRazao_Social As String = "", fComposicao As String = "", fTamanho As String = "", fSeq As String = "", fRamo As String = "", fComposicao_Barra As String = "", fDir_Fotos As String = ""
    Enum enuComposicao
        Colecao = 0
        Grupo = 1
        Linha = 2
        Material = 3
        Modelo = 4
        Comprador = 5
        Cor = 6
        Tamanho = 7
    End Enum
    Public Function VerificaFoto(ByRef parReferencia As String) As Boolean
        If IO.File.Exists(Dir_Fotos & parReferencia & ".png") Then
            parReferencia = Dir_Fotos & parReferencia & ".png"
            Return True
        ElseIf IO.File.Exists(Dir_Fotos & parReferencia & ".bmp") Then
            parReferencia = Dir_Fotos & parReferencia & ".bmp"
            Return True
        ElseIf IO.File.Exists(Dir_Fotos & parReferencia & ".jpg") Then
            parReferencia = Dir_Fotos & parReferencia & ".jpg"
            Return True
        Else
            Return False
        End If
    End Function
    Private fMultRede As Boolean
    Public Property MultRede() As Boolean
        Get
            Return fMultRede
        End Get
        Set(ByVal value As Boolean)
            fMultRede = value
        End Set
    End Property

    Public Property Codigo() As String
        Get
            Return fCodigo
        End Get
        Set(ByVal value As String)
            fCodigo = value
        End Set
    End Property
    Public Property Razao_Social() As String
        Get
            Return fRazao_Social
        End Get
        Set(ByVal value As String)
            fRazao_Social = value
        End Set
    End Property
    Public Property Composicao() As String
        Get
            Return fComposicao
        End Get
        Set(ByVal value As String)
            fComposicao = value
        End Set
    End Property
    Public Property Composta() As Byte
        Get
            Return fComposta
        End Get
        Set(ByVal value As Byte)
            fComposta = value
        End Set
    End Property
    Public Property Unica() As Byte
        Get
            Return fUnica
        End Get
        Set(ByVal value As Byte)
            fUnica = value
        End Set
    End Property
    Public Property Tamanho() As String
        Get
            Return fTamanho
        End Get
        Set(ByVal value As String)
            fTamanho = value
        End Set
    End Property
    Public Property Seq() As String
        Get
            Return fSeq
        End Get
        Set(ByVal value As String)
            fSeq = value
        End Set
    End Property
    Public Property Ramo() As String
        Get
            Return fRamo
        End Get
        Set(ByVal value As String)
            fRamo = value
        End Set
    End Property
    Public Property Composicao_Barra() As String
        Get
            Return fComposicao_Barra
        End Get
        Set(ByVal value As String)
            fComposicao_Barra = value
        End Set
    End Property
    Public Property Tamanho_Barra() As Byte
        Get
            Return fTamanho_Barra
        End Get
        Set(ByVal value As Byte)
            fTamanho_Barra = value
        End Set
    End Property
    Public Property Arredonda() As Byte
        Get
            Return fArredonda
        End Get
        Set(ByVal value As Byte)
            fArredonda = value
        End Set
    End Property
    Public Property Preco() As Byte
        Get
            Return fPreco
        End Get
        Set(ByVal value As Byte)
            fPreco = value
        End Set
    End Property
    Public Property Formata() As Byte
        Get
            Return fFormata
        End Get
        Set(ByVal value As Byte)
            fFormata = value
        End Set
    End Property
    Public ReadOnly Property FormatPreco() As String
        Get
            Return "{0:c" & Preco_Decimal.ToString & "}"
        End Get
    End Property
    Public ReadOnly Property FormatQtd() As String
        Get
            Return "0" & IIf(Qtd > 0, "0," & "".PadRight(Qtd, "0"), "")
        End Get
    End Property
    Public Property Propria() As Byte
        Get
            Return fPropria
        End Get
        Set(ByVal value As Byte)
            fPropria = value
        End Set
    End Property
    Public Property Preco_Decimal() As Byte
        Get
            Return IIf(fPreco_Decimal = 0, 2, fPreco_Decimal)
        End Get
        Set(ByVal value As Byte)
            fPreco_Decimal = value
        End Set
    End Property
    Public Property Composta2() As Byte
        Get
            Return fComposta2
        End Get
        Set(ByVal value As Byte)
            fComposta2 = value
        End Set
    End Property
    Public Property Unica2() As Byte
        Get
            Return fUnica2
        End Get
        Set(ByVal value As Byte)
            fUnica2 = value
        End Set
    End Property
    Public Property Arredonda2() As Byte
        Get
            Return fArredonda2
        End Get
        Set(ByVal value As Byte)
            fArredonda2 = value
        End Set
    End Property
    Public Property Preco2() As Byte
        Get
            Return fPreco2
        End Get
        Set(ByVal value As Byte)
            fPreco2 = value
        End Set
    End Property
    Public Property Formata2() As Byte
        Get
            Return fFormata2
        End Get
        Set(ByVal value As Byte)
            fFormata2 = value
        End Set
    End Property
    Public Property Propria2() As Byte
        Get
            Return fPropria2
        End Get
        Set(ByVal value As Byte)
            fPropria2 = value
        End Set
    End Property
    Public Property Dir_Fotos() As String
        Get
            If Right(fDir_Fotos, 1) <> "\" Then fDir_Fotos &= "\"
            Return fDir_Fotos
        End Get
        Set(ByVal value As String)
            fDir_Fotos = value
        End Set
    End Property
    Public Property Atacado() As Byte
        Get
            Return fAtacado
        End Get
        Set(ByVal value As Byte)
            fAtacado = value
        End Set
    End Property
    Public Property Qtd() As Byte
        Get
            Return fQtd
        End Get
        Set(ByVal value As Byte)
            fQtd = value
        End Set
    End Property
    Public Property Comunicacao() As Byte
        Get
            Return fComunicacao
        End Get
        Set(ByVal value As Byte)
            fComunicacao = value
        End Set
    End Property
    Public Property Pedido() As Byte
        Get
            Return fPedido
        End Get
        Set(ByVal value As Byte)
            fPedido = value
        End Set
    End Property
    Public Property Distribuicao() As Byte
        Get
            Return fDistribuicao
        End Get
        Set(ByVal value As Byte)
            fDistribuicao = value
        End Set
    End Property
    Public Property Cor_Fornecedor() As Byte
        Get
            Return fCor_Fornecedor
        End Get
        Set(ByVal value As Byte)
            fCor_Fornecedor = value
        End Set
    End Property
    Public Property Fidelidade() As Byte
        Get
            Return fFidelidade
        End Get
        Set(ByVal value As Byte)
            fFidelidade = value
        End Set
    End Property
    Private Sub clsFilial_ListaCampo(ByVal ParAcao As enuTConexao, ByRef parErro As Boolean) Handles Me.ListaCampo
        fNomeTabela = "EMPRESAS"
        AlimentaCampo("EMP_CODIGO", fCodigo, True)
        AlimentaCampo("EMP_RAZAO_SOCIAL", fRazao_Social, False)
        AlimentaCampo("EMP_COMPOSICAO", fComposicao, False)
        AlimentaCampo("EMP_COMPOSTA", fComposta, False)
        AlimentaCampo("EMP_UNICA", fUnica, False)
        AlimentaCampo("EMP_TAMANHO", fTamanho, False)
        AlimentaCampo("EMP_SEQ", fSeq, False)
        AlimentaCampo("EMP_RAMO", fRamo, False)
        AlimentaCampo("EMP_COMPOSICAO_BARRA", fComposicao_Barra, False)
        AlimentaCampo("EMP_TAMANHO_BARRA", fTamanho_Barra, False)
        AlimentaCampo("EMP_ARREDONDA", fArredonda, False)
        AlimentaCampo("EMP_PRECO", fPreco, False)
        AlimentaCampo("EMP_FORMATA", fFormata, False)
        AlimentaCampo("EMP_PROPRIA", fPropria, False)
        AlimentaCampo("EMP_PRECO_DECIMAL", fPreco_Decimal, False)
        AlimentaCampo("EMP_COMPOSTA2", fComposta2, False)
        AlimentaCampo("EMP_UNICA2", fUnica2, False)
        AlimentaCampo("EMP_ARREDONDA2", fArredonda2, False)
        AlimentaCampo("EMP_PRECO2", fPreco2, False)
        AlimentaCampo("EMP_FORMATA2", fFormata2, False)
        AlimentaCampo("EMP_PROPRIA2", fPropria2, False)
        AlimentaCampo("EMP_DIR_FOTOS", fDir_Fotos, False)
        AlimentaCampo("EMP_ATACADO", fAtacado, False)
        AlimentaCampo("EMP_QTD", fQtd, False)
        AlimentaCampo("EMP_COMUNICACAO", fComunicacao, False)
        AlimentaCampo("EMP_PEDIDO", fPedido, False)
        AlimentaCampo("EMP_DISTRIBUICAO", fDistribuicao, False)
        AlimentaCampo("EMP_COR_FORNECEDOR", fCor_Fornecedor, False)
        AlimentaCampo("EMP_FIDELIDADE", fFidelidade, False)
    End Sub
    Public Sub New(ByVal parCodigo As String, Optional ByRef parAchou As Boolean = False)
        fCodigo = parCodigo
        parAchou = Processar(enuTConexao.Consulta)
    End Sub
    Public Function ValidaComposicao(ByVal parComposicao As enuComposicao) As Boolean
        Select Case parComposicao
            Case enuComposicao.Colecao
                Return InStr(fComposicao, "C") > 0
            Case enuComposicao.Grupo
                Return InStr(fComposicao, "G") > 0
            Case enuComposicao.Linha
                Return InStr(fComposicao, "L") > 0
            Case enuComposicao.Material
                Return InStr(fComposicao, "M") > 0
            Case enuComposicao.Modelo
                Return InStr(fComposicao, "O") > 0
            Case enuComposicao.Comprador
                Return InStr(fComposicao, "P") > 0
            Case enuComposicao.Tamanho
                If InStr(fComposicao, "S") = 0 Then
                    Return InStr(fComposicao_Barra, "T") > 0
                Else
                    Return False
                End If
            Case enuComposicao.Cor
                If InStr(fComposicao, "S") = 0 Then
                    Return InStr(fComposicao_Barra, "C") > 0
                Else
                    Return False
                End If
            Case Else
                Return False
        End Select
    End Function
    Public Sub New()

    End Sub
End Class
